package com.lxx.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.lxx.entity.Page;
import com.lxx.entity.User;
import com.lxx.service.ISystemService;
import com.lxx.utils.StringUtils;

/**
 * 用户Controller
 * @author lxx
 * @version 2017-11-29
 */
@Controller
@RequestMapping(value = "/sys/user")
public class UserController {

	@Autowired
	private ISystemService systemService;
	@ModelAttribute
	public User get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return systemService.getUser(id);
		}else{
			return new User();
		}
	}

	@RequestMapping(value = {"/list", "/"})
	public String list(User user, HttpServletRequest request, HttpServletResponse response, Map<String,Object> map) {
		//User currentUser = UserUtils.getUser();
		//user.setCurrentUser(currentUser);
		Page<User> page = systemService.findUser(new Page<User>(request, response), user);
        map.put("page", page);
		return "boot/userList";
	}
}